package com.twu.biblioteca;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.HashMap;
import java.util.Map;

public class Library {
    private Map<Integer, String> books;
    private BufferedReader reader;
    private java.io.PrintStream stream;


    public Library(PrintStream stream) {
        this.stream = stream;
        reader = new BufferedReader(new InputStreamReader(System.in));
        books = new HashMap<Integer, String>();
        books.put(1, "The Secret");
        books.put(2, "The tales of two cities");
        books.put(3, "The Lord of the Rings");
        books.put(4, "Think and grow Rich");
        books.put(5, "The Eagle has landed");
        books.put(6, "Black Beauty");
    }

    public void displayBooksAvailable() {
        for (Integer key : books.keySet()) {
            stream.println(key + "." + books.get(key));
        }
    }

    public void reserveBook() throws IOException {
        stream.println("Please enter the book number you want to reserve");
        String option = reader.readLine();
        int optionSelected = Integer.parseInt(option);
        if (books.containsKey(optionSelected)) {
            stream.println("Thank You! Enjoy the book");
        } else {
            throw new IllegalArgumentException("Sorry we don't have that book yet.");
        }
    }
}
